//Test input data generator
//Simulates the input data from a car
//Made by Jason Furente for Autolytics and the AutoBiography Project
// Updated by Evan McCullough 4-14-11

import java.io.*;
import java.util.Random;
import java.text.*;

public class phonyblue
{
	public phonyblue(String fName) 
	{
		int n=1929819;
		String filename= fName;

                int rpm, engineTemp, tirePressure, mileage, internalTemp, externalTemp, callTime, brakeFluidLife;   // These are ints in the DB.
                double fuelEconomy, oilLife, fuelLevel, timeInN, timeInD, timeInR, timeIn1, timeIn2, timeIn3, radioFreq;  // These are floats in the DB
                String make="", model="", year, vin, transStatus, infoStatus, connected, cd, iPod, fanSpeed, climateStatus, phoneConnected, comStatus, headlightStatus, powerOutlets, internalLights, suspStatus, brakeStatus, steeringStatus, dateTime; //These are VarChars in the DB.

                DecimalFormat df = new DecimalFormat("#.#");
		Random generator = new Random();

		boolean check=false;

                //VIN Generator
                vin ="";
                for(int i=0; i<17; i++){
                  vin = vin+Integer.toString(generator.nextInt(10));
                }

                // Make-Model Generator
                int r = generator.nextInt(4)+1;
                switch(r){
                case 1: 
                  make = "Ford"; 
                  r = generator.nextInt(4)+1;
                  switch(r){
                  case 1: model = "F-150"; break;
                  case 2: model = "Ranger"; break;
                  case 3: model = "Mustang"; break;
                  case 4: model = "Focus"; break;
                  }
                  break;
                case 2:
                  make = "Chevrolet";
                  r = generator.nextInt(4)+1;
                  switch(r){
                  case 1: model = "Silverado"; break;
                  case 2: model = "Impala"; break;
                  case 3: model = "TrailBlazer"; break;
                  case 4: model = "Camaro"; break;
                  } 
                  break;
                case 3:
                  make = "Dodge";
                  r = generator.nextInt(4)+1;
                  switch(r){
                  case 1: model = "Charger"; break;
                  case 2: model = "GrandCaravan"; break;
                  case 3: model = "Durango"; break;
                  case 4: model = "Challenger"; break;
                  } 
                  break;
                case 4:
                  make = "Pontiac";
                  r = generator.nextInt(4)+1;
                  switch(r){
                  case 1: model = "Sunfire"; break;
                  case 2: model = "GrandPrix"; break;
                  case 3: model = "Montana"; break;
                  case 4: model = "G6"; break;
                  } 
                  break;
                }
                  
                year = Integer.toString(generator.nextInt(15)+1996);  
		
		//Engine:
		engineTemp=generator.nextInt(150) + 150;
		rpm=generator.nextInt(1000)+ 3000;
		mileage=generator.nextInt(30)+10;
                
                double temp;
		fuelEconomy=generator.nextDouble()*50.0;
                temp = Double.valueOf(df.format(fuelEconomy));
                fuelEconomy = temp;
		oilLife=generator.nextDouble()*100.0;
                temp = Double.valueOf(df.format(oilLife));
                oilLife = temp;
		fuelLevel=generator.nextDouble()*100.0;
                temp = Double.valueOf(df.format(fuelLevel));
                fuelLevel = temp;
		
		//Transmission:
		int blah=generator.nextInt(6)+1;
		switch (blah){
                case 1: transStatus="Good"; break;
                case 2: transStatus="Bad"; break;
                default: transStatus="Good"; break;
		}
		
                timeInD=generator.nextInt(100);
		timeIn3=generator.nextInt(100-(int)timeInD);
		timeIn2=generator.nextInt(100-(int)timeInD-(int)timeIn3);
		timeIn1=generator.nextInt(100-(int)timeInD-(int)timeIn3- (int)timeIn2);
		timeInR=generator.nextInt(100-(int)timeIn3-(int)timeIn2-(int)timeIn1-(int)timeInD);
                timeInN= 100-timeIn3-timeIn2-timeIn1-timeInD-timeInR;

		//Infotainment:
		int blah2=generator.nextInt(6)+1;
		switch (blah2) 
		{
			case 1: infoStatus="Good"; break;
			case 2: infoStatus="Bad"; break;
			default: infoStatus="Good"; break;
		}
		int yn=generator.nextInt(2);
		if(yn==1) connected="y";
		else connected="n";
		
		int blah3=generator.nextInt(8)+1;
		switch (blah3) 
		{
			
                case 1: radioFreq=92.7; break;
                case 2: radioFreq=97.9; break;
                case 3: radioFreq=96.1; break;
                case 4: radioFreq=102.5; break;
                case 5: radioFreq=100.3; break;
                case 6: radioFreq=87.5; break;
                case 7: radioFreq=105.9; break;
                case 8: radioFreq=102.1; break;                        
                default: radioFreq=96.7; break;
		}
		
		int ny=generator.nextInt(2);
		if(ny==1) cd="y";
		else cd="n";
		
		yn=generator.nextInt(2);
		if(yn==1) iPod="y";
		else iPod="n";
		
		//Climate:
		internalTemp=generator.nextInt(80);
		externalTemp=generator.nextInt(110);
		
		int blah4=generator.nextInt(4)+1;
		switch (blah4){
                case 1: fanSpeed="Low"; break;
                case 2: fanSpeed="Med"; break;
                case 3: fanSpeed="High"; break;
                case 4: fanSpeed = "Off"; break;                    
                default: fanSpeed="Off"; break;
		}
		
		int blah5=generator.nextInt(6)+1;
		switch (blah5) 
		{
			case 1: climateStatus="Good"; break;
			case 2: climateStatus="Bad"; break;
			default: climateStatus="Good"; break;
		}
		
		//Communication:
		yn=generator.nextInt(2);
		if(yn==1) phoneConnected="Y";
		else phoneConnected="N";
		
		callTime=generator.nextInt(100000);
		
                int blah6=generator.nextInt(6)+1;
                switch (blah6) 
                {
			case 1: comStatus="Good"; break;
			case 2: comStatus="Bad"; break;
			default: comStatus="Good"; break;
		}
		
		//Lighting/Electrical:
		
                headlightStatus = "";
		int blah7=generator.nextInt(6)+1;
		if(blah7==1){
                  blah7 = generator.nextInt(4)+1;
                  if(blah7==1) headlightStatus="FrontD";
                  if(blah7==2) headlightStatus="FrontP";
                  if(blah7==3) headlightStatus="RearD";
                  if(blah7==4) headlightStatus="RearP";
		}
                else{
                  headlightStatus="Good";
                }
		
		int blah8=generator.nextInt(6)+1;
		switch (blah8) 
		{
			case 1: powerOutlets="Good"; break;
			case 2: powerOutlets="Bad"; break;
			default: powerOutlets="Good"; break;
		}
		
		int blah9=generator.nextInt(6)+1;
		switch (blah9) 
		{
			case 1: internalLights="Good"; break;
			case 2: internalLights="Bad"; break;
			default: internalLights="Good"; break;
		}
		
		//Suspension, Brakes, Tires, and Steering:
		tirePressure=generator.nextInt(15)+25;
		
		int blah10=generator.nextInt(8)+1;
		switch (blah10) 
		{
			case 1: suspStatus="Good"; break;
			case 2: suspStatus="Bad"; break;
			default: suspStatus="Good"; break;
		}
		
                brakeStatus = "";
		blah10=generator.nextInt(8)+1;
		switch (blah10) 
		{
			case 1: brakeStatus="Good"; break;
			case 2: brakeStatus="Bad"; break;
			default: brakeStatus="Good"; break;
		}
		
                steeringStatus = "";
		int blah12=generator.nextInt(8)+1;
		switch (blah12) 
		{
			case 1: steeringStatus="Good"; break;
			case 2: steeringStatus="Bad"; break;
			default: steeringStatus="Good"; break;
		}
                
		brakeFluidLife=generator.nextInt(12);


		String data = make+" "+model+" "+year+" "+vin+ " " + Integer.toString(rpm) + " "+Integer.toString(engineTemp)+" "+ Integer.toString(tirePressure) + " " + Double.toString(fuelEconomy) + " " +Integer.toString(mileage)+" "+Double.toString(oilLife) + " " + Double.toString(fuelLevel) + " " + transStatus+ " " + Double.toString(timeInN) + " " + Double.toString(timeInD) + " " + Double.toString(timeInR) + " " + Double.toString(timeIn3) + " " + Double.toString(timeIn2) + " " +Double.toString(timeIn1)+" "+ infoStatus+ " " +Double.toString(radioFreq)+" " +connected+ " " +cd+ " " + iPod+ " " +Integer.toString(internalTemp) + " " + Integer.toString(externalTemp)+ " " + fanSpeed + " " + climateStatus + " " + phoneConnected + " " + Integer.toString(callTime)+ " " + comStatus+ " " + headlightStatus+ " " + powerOutlets+ " " + internalLights  + " " + suspStatus + " " + Integer.toString(brakeFluidLife)+ " " + brakeStatus+ " " + steeringStatus;
		
		System.out.println(data);
		
		try
		{
                  File file = new File(filename);
                  boolean exist = file.createNewFile();
                  if (!exist){
                    System.out.println("File already exists.");
                    file.delete();

                    FileWriter fstream = new FileWriter(filename);
                    BufferedWriter out = new BufferedWriter(fstream);
                    out.write(data);
                    out.close();
                    System.out.println("File created successfully.");
                  }
                  else
                    {
                      FileWriter fstream = new FileWriter(filename);
                      BufferedWriter out = new BufferedWriter(fstream);
                      out.write(data);
                      out.close();
                      System.out.println("File created successfully.");
                    }
		}catch (IOException ioe)
                  {
                    System.out.println("File Writing error");
                    System.exit(1);
                  }		
	}
}
